﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : CharacterBase {

    /// <summary>
    /// 身份
    /// </summary>
    private Identity identity;
    public CharacterUI characterUI;

    public Identity Identity
    {
        get
        {
            return identity;
        }

        set
        {
            identity = value;
            characterUI.SetIdentity(value);
        }
    }



    /// <summary>
    /// 添加卡牌
    /// </summary>
    /// <param name="card"></param>
    public override void AddCard(Card card,bool isSelected)
    {
        base.AddCard(card, isSelected);
        
        characterUI.SetRemain(CardCount);
    }
    /// <summary>
    /// 发牌
    /// </summary>
    /// <param name="card"></param>
    public override Card DealCard()
    {
        Card card = base.DealCard();
        characterUI.SetRemain(CardCount);
        return card;
    }
    /// <summary>
    /// 排序
    /// </summary>
    /// <param name="asc"></param>
    public override void Sort(bool asc)
    {
        base.Sort(asc);
    }
    //临时的变量
    List<CardUI> tempCardUI = null;
    List<Card> tempCard = null;
    /// <summary>
    /// 选择中手牌
    /// </summary>
    /// <returns></returns>
    public List<Card> FindSelectCards()
    {
        CardUI[] cardUIs = CreatePoint.GetComponentsInChildren<CardUI>();

         tempCardUI = new List<CardUI>();
         tempCard = new List<Card>();

        for (int i = 0; i < cardUIs.Length; i++)
        {
            if (cardUIs[i].IsSelected)
            {
                tempCardUI.Add(cardUIs[i]);
                tempCard.Add(cardUIs[i]._Card);
            }
        }
        //排序
        Tools.Sort(tempCard, true);
        return tempCard;
    }
    /// <summary>
    /// 删除手中的卡牌
    /// </summary>
    public void DelateCardUI()
    {
        if (tempCard == null || tempCardUI == null)
        {
            return;
        }
        for (int i = 0; i < tempCard.Count; i++)
        {
            tempCardUI[i].Destroy();//删除UI
            CardList.Remove(tempCard[i]);//移除手中的手牌集合
        }
        //重新把手上的牌进行排序和计数
        Sort(false);
        characterUI.SetRemain(CardCount);
    }
    /// <summary>
    /// 更新分数
    /// </summary>
    /// <param name="integration"></param>
    public void ShowIntagration(int integration)
    {
        characterUI.SetIntegration(integration);

    }
}
